package com.exsun.gateway.jt809.handler;

import exsun.jt808.data.base.StatusResult;
import exsun.jt808.data.distribute_data.DistributeEntity;
import exsun.jt808.data.util.GsonUtils;
import exsun.jt808.data.util.HttpUtil;
import org.apache.catalina.util.URLEncoder;

import java.nio.charset.Charset;

public class HttpRequest {

//   HttpRequest public static StatusResult postOrder(String httpRequestUrl, DistributeEntity entity, int timeout){
//
//        String str = HttpUtil.sendPost(httpRequestUrl + "/KafkaApi/distributeInner?distributeContent="
//                        + GsonUtils.getJsonFromObject(entity),"",
//                3000,3000,"UTF-8");
//        StatusResult result = GsonUtils.getObjectFromJson(str, StatusResult.class);
//        return result;
//    }

    public static StatusResult postOrder(String httpRequestUrl, DistributeEntity entity, int timeout){
        URLEncoder encoder = new URLEncoder();
        String str = HttpUtil.sendPost(httpRequestUrl + "/KafkaApi/distributeInner?distributeContent="
                        + encoder.encode(GsonUtils.getJsonFromObject(entity), Charset.defaultCharset()),"",
                3000,3000,"UTF-8");
        StatusResult result = GsonUtils.getObjectFromJson(str, StatusResult.class);
        return result;
    }
}
